
<script>
var all_ip = {$items_json};

{literal}
jQuery(document).ready(function () {
	
	jQuery(".txtSearch").blur(function(){
	        if(jQuery(this).attr('value') == '') jQuery(this).attr('value',jQuery(this).attr('title'));
	        });
	    jQuery(".txtSearch").focus(function(){
	        if(jQuery(this).attr('value') == jQuery(this).attr('title')) jQuery(this).attr('value','');});
	    
	    jQuery(".txtSearch").keyup(function(event){
	    	var d = jQuery(this).attr('value');
		        d = d.toLowerCase();
	    	if(event.keyCode != 13 && d)  {  
		        var return_arr = new Array();
		        for(i in all_ip)
				{
					str = all_ip[i].ip;
					str = str.toLowerCase();
					if(str.match(d))
					{
						return_arr.push(all_ip[i]);
					}
				}
				print_ip(return_arr);
	    	}
	    	if(!d)  {  
				print_ip(all_ip);
	    	}
	    });
});
function print_ip(value)
{
	document.getElementById("list_ip").innerHTML = '';
	html = '';
	if(value != '')
	{
		
		var i = 0;
		for(v in value){
			if(Array.prototype[v]) continue;
			i++;
			bg_color = (i%2 == 0) ? '#f0f0f0' : '#ffffff';
			html += '<tr bgcolor="'+bg_color+'">';
			html += '<td width="3%"><input name="chk_id[]" type="checkbox" id="list_item_'+value[v]['id']+'" value="'+value[v]['id']+'" title="'+value[v]['id']+'"></td>';
			html += '<td width="10%" id="ban_ip_ip_'+value[v]['id']+'">'+value[v]['ip']+'</td>';
			html += '<td id="ban_ip_reason_'+value[v]['id']+'">'+value[v]['reason']+'</td>';
			html += '<td width="10%" id="ban_ip_username_'+value[v]['id']+'"><a href="'+value[v]['user_name']+'">'+value[v]['user_name']+'</a></td>';
			html += '<td width="10%" id="ban_ip_time_'+value[v]['id']+'">'+value[v]['create_time']+'</td>';
			html += '<td align="center" width="7%" id="ban_ip_action_'+value[v]['id']+'">';
			html += '<a onclick="if(!confirm(\'Bạn có chắc muốn xóa không?\'))return false;" href="manage_ban_ip.html?act=del&id='+value[v]['id']+'">';
			html += '<img src="style/images/admin/delete1.gif" title="Xóa" />';
			html += '</a>';
			html += '<a onclick="edit_ban_ip('+value[v]['id']+',\''+value[v]['ip']+'\',\''+value[v]['reason']+'\')" href="javascript:void(0);">';
			html += '<img src="style/images/admin/edit.gif" width="16" title="sửa" />';
			html += '</a>';
			html += '</td>';
			html += '</tr>';
			
		}
		
	}
	else{
		html += '<tr>';
		html += '<td colspan="6">Chưa có ip này</td>';
		html += '</tr>';
	}
	document.getElementById("list_ip").innerHTML = html;
}
function edit_ban_ip(id,ip,reason){
	var title = (id) ? 'Sửa' : 'Thêm' ;
	var id_edit = (id) ? id : '' ;
	var ip_edit = (ip) ? ip : '' ;
	var reason_edit = (reason) ? reason : '' ;
	html_content = '<div style="width:400px;border:1px solid #d1d4d3; background-color:#fff; padding:1px;" align="left" id="block_mini_message">';
	html_content +=		'<div style=" height:26px; background-color:#17437a" align="left">';
	html_content +=			'<span style="line-height:26px;color: #fff; padding-left:10px;">'+title+' ip</span>';
	html_content +=		'</div>';
	html_content +=		'<div style=" background:url(style/images/bg_log_faile.gif) repeat-x bottom; padding:10px">';
	html_content +=			'<input type="hidden" name="ban_id" id="ban_id" value="'+id_edit+'" />';
	html_content +=			'<input type="text" name="ban_ip" id="ban_ip" value="'+ip_edit+'" style="margin-bottom:10px;width:95%" />';
	html_content +=			'<textarea name="ban_reason" id="ban_reason" rows="5" class="textAreReplyFeedback rongbay_bbcode" style="margin:0;width:96%">'+reason_edit+'</textarea>';
	html_content +=			'<div style=" margin-top:10px; padding-bottom:5px;" align="right">';
	html_content +=				'<div align="right" class="btnAllFeedback" onmouseout="this.className=\'btnAllFeedback\'"  onmouseover="this.className=\'btnAllFeedbackHover\'" style=" margin-right:10px;_margin-right:5px; margin-left:10px;*margin-left:5px; width:50px;float:left;" id="close_reason">Đóng</div>';
	html_content +=				'<div align="right" class="btnAllFeedback" onmouseout="this.className=\'btnAllFeedback\'"  onmouseover="this.className=\'btnAllFeedbackHover\'" style=" margin-right:10px;_margin-right:5px; width:100px;" onclick="ajax_ban_ip();" id="send_reason">'+title+' ip</div>';
	html_content +=	'</div></div></div>';
	html_content +=		'</div>';
	
	jQuery.blockUI({message: html_content,css: { border:'none', padding:0}});
	jQuery('#close_reason').click(function () { 
		jQuery.unblockUI();
	}); 
}
function ajax_ban_ip(){
	var ban_id = document.getElementById('ban_id').value;
	var ban_ip = document.getElementById('ban_ip').value;
	var ban_reason = document.getElementById('ban_reason').value;
	
	jQuery.post(WEB_DIR+"ajax.php?act=admin&code=add_edit_ban_ip", {		
			ban_id		:ban_id,
			ban_ip		:ban_ip,
			ban_reason	:ban_reason
	},
			function(msg){
				if(msg=='not_perm')
				{
					log_faile('Bạn không có quyền thực hiện chức năng này.');
					return false;
				}
				else if(msg=='not_ip')
				{
					log_faile('Bạn đã chưa nhập ip.');
					return false;
				}
				else{
					var value = msg;
					
					
					if(!ban_id){
						html = '<tr >';
						html += '<td width="3%"><input name="chk_id[]" type="checkbox" id="list_item_'+value['id']+'" value="'+value['id']+'" title="'+value['id']+'"></td>';
						html += '<td width="10%" id="ban_ip_ip_'+value['id']+'">'+value['ip']+'</td>';
						html += '<td id="ban_ip_reason_'+value['id']+'">'+value['reason']+'</td>';
						html += '<td width="10%" id="ban_ip_username_'+value['id']+'"><a href="'+value['user_name']+'">'+value['user_name']+'<a href="'+value['user_name']+'"></td>';
						html += '<td width="10%" id="ban_ip_time_'+value['id']+'">'+value['create_time']+'</td>';
						html += '<td align="center" width="7%" id="ban_ip_action_'+value['id']+'">';
						html += '<a onclick="if(!confirm(\'Bạn có chắc muốn xóa không?\'))return false;" href="manage_ban_ip.html?act=del&id='+value['id']+'">';
						html += '<img src="style/images/admin/delete1.gif" title="Xóa" />';
						html += '</a>';
						html += '<a onclick="edit_ban_ip('+value['id']+',\''+value['ip']+'\',\''+value['reason']+'\')" href="javascript:void(0);">';
						html += '<img src="style/images/admin/edit.gif" width="16" title="sửa" />';
						html += '</a>';
						html += '</td>';
						html += '</tr>';
						jQuery("#list_ip").append(html);
					}
					else{
						document.getElementById("ban_ip_ip_"+value['id']).innerHTML = value['ip'];
						document.getElementById("ban_ip_reason_"+value['id']).innerHTML = value['reason'];
						document.getElementById("ban_ip_username_"+value['id']).innerHTML = '<a href="'+value['user_name']+'">'+value['user_name']+'<a href="'+value['user_name']+'">';
						document.getElementById("ban_ip_time_"+value['id']).innerHTML = value['create_time'];
						document.getElementById("ban_ip_action_"+value['id']).innerHTML = '<a onclick="if(!confirm(\'Bạn có chắc muốn xóa không?\'))return false;" href="manage_ban_ip.html?act=del&id='+value['id']+'"><img src="style/images/admin/delete1.gif" title="Xóa" /></a><a onclick="edit_ban_ip('+value['id']+',\''+value['ip']+'\',\''+value['reason']+'\')" href="javascript:void(0);"><img src="style/images/admin/edit.gif" width="16" title="sửa" /></a>';
					}
					jQuery.unblockUI();
					return false;
				}
				
			},'json'
		);
}
{/literal}
</script>
<div align="left">
<font style="color:#0000CC; font-size:14px"><strong><a href="manage_ban_ip.html">Quản lý khoá ip</a></strong></font>
<div style="padding:10px 0">
	<input type="text" value="Tìm kiếm" class="txtSearch" title="Tìm kiếm"/>
</div>
<div style="padding-bottom:10px">
	<input onclick="if(!confirm('Bạn có chắc muốn xóa không?'))return false;" type="submit" name="del_all" id="del_all" value="Xóa ip được chọn" title="Xóa ip được chọn"/>
	<input type="button" onclick="edit_ban_ip('','','')" name="add_item" id="add_item" value="Thêm Ip" title="thêm Ip"/>
</div>

<table width="100%" cellpadding="6" border="1" style="border-collapse:collapse;border-color:#bbb">
	
	<tr bgcolor="#ddd">
		<td width="3%">
			<input onClick="selecte_all_checkbox('ManageBanIpForm');" name="chk_ids" type="checkbox" id="list_item_0" value="1" title="Chọn tất cả">
		</td>
		<td width="10%">
			<strong>Ip</strong>
		</td>
		<td>
			<strong>Lý do khoá</strong>
		</td>
		<td width="10%">
			<strong>Người khoá</strong>
		</td>
		<td width="10%">
			<strong>Thời gian</strong>
		</td>
		<td width="7%">
			<strong>Hành động</strong>
		</td>
	</tr>
</table>
<table width="100%" cellpadding="6" border="1" style="border-collapse:collapse;border-color:#bbb" id="list_ip">
	{if $items}
		{foreach from=$items item=items}
	<tr bgcolor="{cycle values='#ffffff,#f0f0f0'}">
		<td width="3%">
			<input name="chk_id[]" type="checkbox" id="list_item_{$items.id}" value="{$items.id}" title="{$items.id}">
		</td>
		<td width="10%" id="ban_ip_ip_{$items.id}">
			{$items.ip}
		</td>
		<td id="ban_ip_reason_{$items.id}">
			{$items.reason}
		</td>
		<td width="10%"  id="ban_ip_username_{$items.id}">
			<a href="{$items.user_name}">{$items.user_name}</a>
		</td>
		<td width="10%" id="ban_ip_time_{$items.id}">
			{$items.create_time}
		</td>
		<td align="center" width="7%" id="ban_ip_action_{$items.id}">
			<a onclick="if(!confirm('Bạn có chắc muốn xóa không?'))return false;" href="manage_ban_ip.html?act=del&id={$items.id}">
					<img src="style/images/admin/delete1.gif" title="Xóa" />
		  	</a>
		  	<a onclick="edit_ban_ip({$items.id},'{$items.ip}','{$items.reason}')" href="javascript:void(0);">
					<img src="style/images/admin/edit.gif" width="16" title="sửa" />
		  	</a>
		</td>
	</tr>
		{/foreach}
	{/if}
</table>
<div style="padding-top:10px">
<input onclick="if(!confirm('Bạn có chắc muốn xóa không?'))return false;" type="submit" name="del_all" id="del_all" value="Xóa ip được chọn" title="Xóa ip được chọn"/>
<input type="button" onclick="edit_ban_ip('','','')" name="add_item" id="add_item" value="Thêm Ip" title="thêm Ip"/>
</div>
</div>